<?php

defined('__MAPEXEC__') or die('No direct access allowed');

class Maps_Map_PolyLine extends Maps_Collection {
  
  private $strokeColor = '#0000FF';
  private $strokeOpacity = 1.0;
  private $strokeWeight = 3;
  
  /**
   * Class constructor.
   * @param   string  Item Id prefix
   * @param   string  Collection Id
   * @return  void
   */
  public function __construct($prefix=null, $id='') {
    parent::__construct($prefix, $id);
  }
  
  /**
   * Adds a latitude/longitude coordinate to this line
   * @param   Maps_LatLng   Latitude/longitude object
   * @return  string        Item Id as "lat,lng"
   */
  public function addCoord(Maps_LatLng $coord) {
    $this->addItem($coord);
    return $coord->__toString();
  }
  
  /**
   * Adds a latitude/longitude coordinate using a Point Of Interest object.
   * @param   Maps_Map_POI  Point of Interest object
   * @return  integer       Number of coordinates in this line
   */
  public function addCoordByPOI(Maps_Map_POI $poi) {
    return $this->addCoord( $poi->getLatLng() );
  }
  
  /**
   * Gets the stroke color for this line.
   * @param   void
   * @return  string  Stroke color
   */
  public function getStrokeColor() {
    return $this->strokeColor;
  }
  
  /**
   * Gets the stroke opacity for this line. Export objects that
   * do not implement stroke opacity will make any non zero
   * opacity fully opaque.
   * @param   void
   * @return  float   Stroke opacity.
   */
  public function getStrokeOpacity() {
    return $this->strokeOpacity;
  }
  
  /**
   * Gets the stroke weight of this line.
   * @param   void
   * @return  string  Stroke weight in pixels
   */
  public function getStrokeWeight() {
    return $this->strokeWeight;
  }
  
  /**
   * Removes a coordinate from the line.
   * @param   string    Item Id as "lat,lng"
   * @return  boolean   True if removed, false otherwise
   */
  public function remove($id) {
    foreach ($this->items as $index => $item) {
      if ($id == $item->__toString()) {
        array_splice($this->items, $index, 1);
        unset($item);
        $this->decrementCount();
        return true;
      }
    }
    return false;
  }
  
  /**
   * Sets the stroke color of this line.
   * @param   string  RGB hex color: #RRGGBB
   * @return  void
   */
  public function setStrokeColor($color='#0000FF') {
    $this->strokeColor = $color;
  }
  
  /**
   * Sets the stroke opacity of this line.
   * @param   float   Opacity value: 0.0 (transparent) to 1.0 (opaque)
   * @return  void
   */
  public function setStrokeOpacity($opacity=1.0) {
    $this->strokeOpacity = $opacity;
  }
  
  /**
   * Sets the stroke weight of this line in pixels.
   * @param   integer   Stroke weight in pixels
   * @return  void
   */
  public function setStrokeWeight($weight=3) {
    $this->strokeWeight = $weight;
  }
  
}

?>